package com.fantasy.getbom;

import java.io.File;
import java.util.HashSet;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import com.fantasy.excel.ReadExcel;
import com.fantasy.file.GetFolderAbsPath;
import com.fantasy.file.WriteTxt;

public class GetAddBom {

	private static HashSet<String> bomList = new HashSet<String>();
	
	public static void getAddSheet(){
		String folderName = "test";
		File xlsFolder = new File(GetFolderAbsPath.getFolderPath(folderName));
		if(xlsFolder.exists()){
			for (File xlsFile : xlsFolder.listFiles()) {
				Workbook wk = ReadExcel.getWorkbook(xlsFile);
				for (Sheet sheet : wk) {
					foreachCol(sheet);
				}
			}
		}else{
			System.out.println("not found file" + xlsFolder.getAbsolutePath());
		}
	}
	
	public static void foreachCol(Sheet sheet){
		for (Row row : sheet) {
			//System.out.println(row.getLastCellNum());
			for (int index = 0 ; index < row.getLastCellNum() ; index ++ ) {
				if(ReadExcel.getCellFormatValue(row.getCell(index)).toUpperCase().equals("ADD")){
					//System.out.println(index);
					String siBom = ReadExcel.getCellFormatValue( row.getCell(index + 1 )).trim();
					if(!"".equals(siBom) && !"N/A".equals(siBom) ){
						bomList.add(siBom);
					}
				}
			}
		}
	}
	
	public static void main(String[] args) {
		WriteTxt.open(GetFolderAbsPath.getPath() + "/siPartList.txt");
		getAddSheet();
		WriteTxt.write("SI Part" + "\n");
		for (String string : bomList) {
			WriteTxt.write(string + "\n");
		}
		WriteTxt.close();
	}
}
